package com.peng.leetcode.array;

import java.util.HashSet;
import java.util.Set;

/**
 * RemoveDuplicates1
 * 26. 删除有序数组中的重复项
 * https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
 *
 * @author: lupeng6
 * @create: 2023/2/23 10:35
 */
public class RemoveDuplicates1 {
    public int removeDuplicates(int[] nums) {
        Set<Integer> s = new HashSet<>();
        int lower = 0;
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (!s.contains(num)) {
                s.add(num);
                nums[lower] = nums[i];
                lower++;
            }
        }
        return s.size();
    }
}
